package dht.mains;

import java.io.IOException;
import java.net.UnknownHostException;
import java.util.ArrayList;

import dht.data.DhtData;
import dht.data.Options;
import dht.node.Node;

public class ClientForceDHTTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws InterruptedException {

		Node mySelf = null;

		int dim = Options.dimensions;
		boolean init = false;
		//String adrrIp = "192.168.1.77";
		String adrrIp="192.168.1.20";
		try {
			mySelf = new Node(dim,init,adrrIp); 
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		mySelf.start();
		
		while (mySelf.readyWork==false) {
			Thread.sleep(10);
		}
		
		System.out.println("coucou je suis arrivé la...");
		System.out.println("Starting to force The DHT :D");
		ArrayList<ArrayList<String>> dests=new ArrayList<ArrayList<String>>();
		for (int i=0;i<30;i++) {
			DhtData<Integer> d=new DhtData<Integer>(i);
			ArrayList<String> where=new ArrayList<String>();
			where.add(d.toString());where.add(d.toString());
			
			if (mySelf.PUT(where,d)==false) {
				System.out.println("oops...bug");
			}
			else { 
				System.out.println("J'ai envoyé : "+d+" sur la DHT");
				dests.add(where);
			}

		}
		int d=0;
		for (ArrayList<String> t : dests) {
			System.out.println("cela devrait être "+d+" que je reçois et je reçois : "+mySelf.GET(t));
			d++;
		}
		
		mySelf.QUIT();
		
		return;
	}

}
